package lambda;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Predicate;

/**
 * 方法引用
 * 1. 指向静态方法的方法引用
 * 2. 指向现有对象的实例方法的方法引用
 *
 * @author Summerday
 */
public class MethodReferenceTest {

    public static List<String> getList(List<String> params, Predicate<String> filter) {
        List<String> res = new LinkedList<>();
        for (String param : params) {
            if (filter.test(param)) {
                res.add(param);
            }
        }
        return res;
    }

    public static boolean isStartWith(String name) {
        return name.startsWith("sum");
    }

    public static void main(String[] args) {
        List<String> params = Arrays.asList("summerday","tqbx","天乔巴夏","summer","");

        //静态方法的方法引用
        List<String> list = getList(params, MethodReferenceTest::isStartWith);
        System.out.println(list);

        // 指向现有对象的实例方法的方法引用
        List<String> sum = getList(params, String::isEmpty);
        System.out.println(sum);

    }
}
